<?php
require_once 'application/library/auth/gcAuth.php';
require_once 'application/constant/navigation.php';
require_once 'application/library/auth/gcUserCompetence.php';
require_once 'application/library/controller/gcLBasicAction.php';

/**
 * gcMBasicAction
 * @author    Soochow University
 * @version   1.0
 * @exclude   作  成  日：2011/04/07
 */
class  gcMBasicAction extends gcLBasicAction{

    /**
     * @see application/library/controller/gcLBasicAction::init()
     */
    public function init(){
        parent::init();
        //$this->userAuthentication();
    }

    /**
     * 用户认证
     * userAuthentication
     */
    private function userAuthentication(){
        $auth = new gcAuth();

        if($auth->isOnline()){
            if($this->isCompetence()){
                return;
            }else{
               $this->redirect(navigation::PERMISSIONS_PAGE);
            }
        }else if($this->isUriIntercept()){
            return;
        }else{
            if ($this->getRequest()->isXmlHttpRequest()){
                $output = array("sysTimeoutErr" => "Timeout");
                jsonHelper::outPutJson($output);
                exit;
            }else{
                $this->redirect(navigation::LOGIN_INDEX);
            }
        }
    }

    /**
     * 访问限制
     * isUriIntercept
     * @return bool
     */
    public function isUriIntercept(){
        $moduleName     = $this->getRequest()->getModuleName();
        $controllerName = $this->getRequest()->getControllerName();
        $actionName     = $this->getRequest()->getActionName();
        $boolReturn     = true;
/*
        foreach (configHelper::getUriIntercept() as $arrayKey=>$value){
            $uri=explode("/",$value);
            if(@strtoupper($uri[0])==@strtoupper($moduleName) 
               && @strtoupper($uri[1])==@strtoupper($controllerName) 
               && @strtoupper($uri[2])==@strtoupper($actionName)){
                return true;
            }else{
                $boolReturn= false;
            }
        }*/
        return $boolReturn;
    }

    /**
     * 资格验证
     * competence
     * @return  boolen
     */
    private function isCompetence(){
        $moduleName     = $this->getRequest()->getModuleName();
        $controllerName = $this->getRequest()->getControllerName();
        $actionName     = $this->getRequest()->getActionName();
        $userCompetence = new gcUserCompetence();
        return $userCompetence->isCompetence($moduleName,$controllerName,$actionName);
    }
    
}